'use strict';
angular.module('clientApp')
.directive('ajouterhotel', function($filter, hotelAPI, ngToast) {
    return {
        restrict : 'E',
        scope : {
            added : '=',
            view : '='
        },
        link : function($scope) {
			
			$scope.values = ['A', 'B', 'C'];
			$scope.IClassification = 'A';
        	  
        	$scope.ajout = function() {
        		var hotel = {};
        		hotel.name = $scope.IName;
        		hotel.address = $scope.IAdresse;
        		hotel.classification = $scope.IClassification;
        		
        		hotelAPI.add(hotel)
        		.success(function(data) {
        			ngToast.create({
    					content: 'L\'hôtel a bien été ajouté',
    					className: 'success'
    				});
        			$scope.added = data;
        			
        			$scope.IName = '';
        			$scope.IAdresse = '';
        			$scope.IClassification = 'A';
            	})
            	.error(function() {
    				ngToast.create({
    					content: 'Erreur de communication avec le serveur',
    					className: 'danger'
    				});
    			});
        	};
        },
        templateUrl : 'views/directiveAjoutHotel.html',
        replace : true
    };
});
